import 'package:baseProjectFlutter/api/ApiMain.dart';
import 'package:baseProjectFlutter/mode/test_data.dart';
import 'package:easy_refresh/easy_refresh.dart';
import 'package:baseProjectFlutter/base/mvvm/base_view_model.dart';

import '../../utils/http/http_ui_handle.dart';
import '../../utils/other/log/log.dart';

class DemoVm extends BaseViewModel {
  DemoVm() : super();

  // 页数
  int _page = 0;

  int get page => _page;

  set page(int value) {
    _page = value;
  }

  List<TestData> _dataList = [];

  List<TestData> get dataList => _dataList;

  set dataList(List<TestData> dataList) {
    _dataList.addAll(dataList);
  }

  Future refreshData({bool isShowLoading = false}) {
    HttpUiHandle handle = HttpUiHandle.get(this);
    return ApiMain.recommend(handle).then((result) {
      if (_page == 0) {
        _dataList.clear();
        refreshController.finishRefresh();
      } else {
        refreshController.finishLoad(IndicatorResult.success);
      }
      LogUtils.e(result);
      _dataList.addAll(result.data);
      _page++;
    });
  }
}
